$(function () {
    var $datagrid = $("#datagrid"), $toolbar = $("#toolbar"), $orderType = $("#orderType"),$orderStatus=$("#orderStatus");
    $("#orderType").combobox({
        onChange:function(oldV,newV){
            $datagrid.datagrid("reload");
            return newV;
        }
    });
    $("#orderStatus").combobox({
        onChange:function(oldV,newV){
            $datagrid.datagrid("reload");
        }
    });
    $(".easyui-datetimebox").combo({
        onChange:function(newV,oldV){
            doSearch();
        }
    })
    $datagrid.datagrid({
        singleSelect: true,
        fit: true,
        border: false,
        fitColumns: true,
        url: Constant.ctx("/mulanweb/admin/order/search"),
        method: 'post',
        pagination: true,
        toolbar: $toolbar,
        columns: [[
            {field: 'Id', title: '编号'},
            {field: 'Mobile_Number', title: '手机号码',formatter:function(v,r,i){
                if(v){
                    return v ;
                }else{
                    return "未填写";
                }
            }},
            {field: 'WechatNickname', title: '昵称'},
            {field: 'Sex', title: '性别',formatter:function(v,r,i){
                if(v == 1){
                    return "男";
                }else if(v== 2){
                    return "女";
                }else{
                    return "未填写";
                }
            }},
            {field:'StatusId',title:'状态',formatter:function (v,r,i){
                if(v == 4){
                    return '已支付';
                }else if(v == 5){
                    return '未支付';
                }else if(v == 6){
                    return '已过期';
                }else if(v == 7){
                    return '已验证';
                }else if(v == 8){
                    return '已评论';
                }else {
                    return v;
                }

            }},
            {field:'CreateTime',title:'下单时间'},
            {field:'VerifyTime',title:'兑换时间',formatter:function(v,r,i){
                if(v){
                    return v;
                }else{
                    return '未兑换';
                }
            }}
        ]],
       onBeforeLoad: function (param) {
            param.PageNumber = param.page;
            param.PageSize = param.rows;
           param.typeId = 24;
           var orderType = $orderType.combo("getValue");
           if(orderType && orderType != 0 ){
               param.targetTypeId = orderType;
           }

           var orderStatus = $("#orderStatus").combo("getValue");
           if(orderStatus && orderStatus!=0){
               param.orderStatus = orderStatus;
           }

           var orderNumber = $("#orderNumber").val();
           if(orderNumber){
               param.orderNumber = orderNumber ;
           }

           var mobile = $("#mobile").val();
           if(mobile){
               param.mobileNumber=mobile;
           }
           var nickname = $("#nickname").val();
           if(nickname){
               param.wechatNickname=nickname;
           }

           var startVerifyTime = $("#startVerifyTime").combo("getValue");
           console.info(startVerifyTime);
           if(startVerifyTime){
               param.startVerifyTime = startVerifyTime;
           }

           var endVerifyTime = $("#endVerifyTime").combo("getValue");
           if(endVerifyTime){
               param.endVerifyTime = endVerifyTime;
           }
            return true;
        },
        loadFilter: function (data) {
            var newData = {};
            if (data.ReturnCode == 1) {
                newData.rows = data.DataList;
                if (newData.rows.length > 0) {
                    newData.total = data.TotalRow;
                } else {
                    newData.total = 0;
                }
            }
            return newData;
        }
    });
});
function doSearch(){
    $("#datagrid").datagrid("reload");
}